<html>
<!-- =====================================================================

  File:      Generated file for Adventure Works Cycles Storefront Sample
  Summary:   Self-documentation for application
  Date:	     June 16, 2003

=====================================================================

  This file is part of the Microsoft SQL Server Code Samples.
  Copyright (C) 2003 Microsoft Corporation.  All rights reserved.

This source code is intended only as a supplement to Microsoft
Development Tools and/or on-line documentation.  See these other
materials for detailed information regarding Microsoft code samples.

THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

======================================================= -->
<head>
  <link rel=stylesheet href=style.css>
</head>
<body>
<div class=SourcePanel style="font-size:12">
<pre style="background-color:white">
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Web</span>.<span style="color: #2040a0">Services</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Configuration</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Globalization</span><span style="color: #4444FF">;</span>

<span style="color: #008000">/* =====================================================================

  File:      InstantOrder.asmx.cs for Adventure Works Cycles Storefront Sample
  Summary:   Web service for placing an immediate order from some other web site.
  Date:	     June 16, 2003

---------------------------------------------------------------------

  This file is part of the Microsoft SQL Server Code Samples.
  Copyright (C) Microsoft Corporation.  All rights reserved.

This source code is intended only as a supplement to Microsoft
Development Tools and/or on-line documentation.  See these other
materials for detailed information regarding Microsoft code samples.

THIS CODE AND INFORMATION ARE PROVIDED &quot;AS IS&quot; WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

======================================================= */</span>

<span style="color: #0000FF"><strong>namespace</strong></span> <span style="color: #2040a0">Microsoft</span>.<span style="color: #2040a0">Samples</span>.<span style="color: #2040a0">SqlServer</span>
<span style="color: #4444FF"><strong>{</strong></span>

	<span style="color: #0000FF"><strong>public</strong></span> <span style="color: #0000FF"><strong>class</strong></span> <span style="color: #2040a0">InstantOrder</span> <span style="color: #4444FF">:</span> <span style="color: #2040a0">WebService</span> 
	<span style="color: #4444FF"><strong>{</strong></span>

		<span style="color: #008000">//*******************************************************</span>
		<span style="color: #008000">//</span>
		<span style="color: #008000">// InstantOrder.OrderItem() Method </span>
		<span style="color: #008000">//</span>
		<span style="color: #008000">// The OrderItem method enables a remote client to programmatically</span>
		<span style="color: #008000">// place an order using a webservice. </span>
		<span style="color: #008000">//</span>
		<span style="color: #008000">//*******************************************************      </span>

		<span style="color: #4444FF">[</span><span style="color: #2040a0">WebMethod</span><span style="color: #4444FF">(</span><span style="color: #2040a0">Description</span><span style="color: #4444FF">=</span><span style="color: #444444">&quot;The OrderItem method enables a remote client to programmatically place an order using a WebService.&quot;</span>, <span style="color: #2040a0">EnableSession</span><span style="color: #4444FF">=</span><span style="color: #0000FF"><strong>false</strong></span><span style="color: #4444FF">)</span><span style="color: #4444FF">]</span>
		<span style="color: #0000FF"><strong>public</strong></span> <span style="color: #2040a0">OrderDetails</span> <span style="color: #2040a0">OrderItem</span><span style="color: #4444FF">(</span><span style="color: #2040a0">string</span> <span style="color: #2040a0">userName</span>, <span style="color: #2040a0">string</span> <span style="color: #2040a0">password</span>, <span style="color: #0000FF"><strong>int</strong></span> <span style="color: #2040a0">productID</span>, <span style="color: #0000FF"><strong>int</strong></span> <span style="color: #2040a0">quantity</span>,
			<span style="color: #2040a0">string</span> <span style="color: #2040a0">addressLine1</span>, <span style="color: #2040a0">string</span> <span style="color: #2040a0">addressLine2</span>, <span style="color: #2040a0">string</span> <span style="color: #2040a0">addressCity</span>, <span style="color: #0000FF"><strong>int</strong></span> <span style="color: #2040a0">addressStateProvinceID</span>, <span style="color: #2040a0">string</span> <span style="color: #2040a0">addressPostalCode</span><span style="color: #4444FF">)</span> 
		<span style="color: #4444FF"><strong>{</strong></span>
        
			<span style="color: #008000">// Login client using provided username and password</span>
			<span style="color: #2040a0">CustomersDB</span> <span style="color: #2040a0">accountSystem</span> <span style="color: #4444FF">=</span> <span style="color: #0000FF"><strong>new</strong></span> <span style="color: #2040a0">CustomersDB</span><span style="color: #4444FF">(</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
			<span style="color: #2040a0">CustomerDetails</span> <span style="color: #2040a0">customerDetails</span> <span style="color: #4444FF">=</span> <span style="color: #2040a0">accountSystem</span>.<span style="color: #2040a0">Login</span><span style="color: #4444FF">(</span><span style="color: #2040a0">userName</span>, <span style="color: #2040a0">password</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
			<span style="color: #2040a0">String</span> <span style="color: #2040a0">customerId</span> <span style="color: #4444FF">=</span> <span style="color: #2040a0">customerDetails</span>.<span style="color: #2040a0">CustomerID</span><span style="color: #4444FF">;</span>
        
			<span style="color: #0000FF"><strong>if</strong></span> <span style="color: #4444FF">(</span><span style="color: #2040a0">customerId</span> <span style="color: #4444FF">=</span><span style="color: #4444FF">=</span> <span style="color: #2040a0">null</span><span style="color: #4444FF">)</span> 
			<span style="color: #4444FF"><strong>{</strong></span>
				<span style="color: #0000FF"><strong>throw</strong></span> <span style="color: #0000FF"><strong>new</strong></span> <span style="color: #2040a0">Exception</span><span style="color: #4444FF">(</span><span style="color: #444444">&quot;Error: Invalid Login!&quot;</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
			<span style="color: #4444FF"><strong>}</strong></span>

			<span style="color: #008000">// Wrap in try/catch block to catch errors in the event that someone types in</span>
			<span style="color: #008000">// an invalid value for quantity</span>
			<span style="color: #0000FF"><strong>int</strong></span> <span style="color: #2040a0">qty</span> <span style="color: #4444FF">=</span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Math</span>.<span style="color: #2040a0">Abs</span><span style="color: #4444FF">(</span><span style="color: #2040a0">quantity</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
			<span style="color: #0000FF"><strong>if</strong></span> <span style="color: #4444FF">(</span><span style="color: #2040a0">qty</span> <span style="color: #4444FF">=</span><span style="color: #4444FF">=</span> <span style="color: #2040a0">quantity</span> <span style="color: #4444FF">&amp;</span><span style="color: #4444FF">&amp;</span> <span style="color: #2040a0">qty</span> <span style="color: #4444FF">&lt;</span> <span style="color: #FF0000">1000</span><span style="color: #4444FF">)</span> 
			<span style="color: #4444FF"><strong>{</strong></span>
        
				<span style="color: #008000">// Add Item to Shopping Cart</span>
				<span style="color: #2040a0">ShoppingCartDB</span> <span style="color: #2040a0">myShoppingCart</span> <span style="color: #4444FF">=</span> <span style="color: #0000FF"><strong>new</strong></span> <span style="color: #2040a0">ShoppingCartDB</span><span style="color: #4444FF">(</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
				<span style="color: #2040a0">myShoppingCart</span>.<span style="color: #2040a0">AddItem</span><span style="color: #4444FF">(</span><span style="color: #2040a0">customerId</span>, <span style="color: #2040a0">productID</span>, <span style="color: #2040a0">qty</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>

				<span style="color: #0000FF"><strong>bool</strong></span> <span style="color: #2040a0">isExtendedProcessing</span> <span style="color: #4444FF">=</span> 
					 <span style="color: #4444FF">(</span><span style="color: #2040a0">ConfigurationSettings</span>.<span style="color: #2040a0">AppSettings</span><span style="color: #4444FF">[</span><span style="color: #444444">&quot;ExtendedOrderProcessing&quot;</span><span style="color: #4444FF">]</span>.<span style="color: #2040a0">ToUpper</span><span style="color: #4444FF">(</span><span style="color: #2040a0">WorldReady</span>.<span style="color: #2040a0">USCulture</span><span style="color: #4444FF">)</span> <span style="color: #4444FF">=</span><span style="color: #4444FF">=</span>
											 <span style="color: #444444">&quot;TRUE&quot;</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
					
				<span style="color: #0000FF"><strong>int</strong></span> <span style="color: #2040a0">addressID</span> <span style="color: #4444FF">=</span>
					<span style="color: #2040a0">accountSystem</span>.<span style="color: #2040a0">AccessCustomerAddress</span><span style="color: #4444FF">(</span><span style="color: #2040a0">Int32</span>.<span style="color: #2040a0">Parse</span><span style="color: #4444FF">(</span>
					<span style="color: #2040a0">customerId</span>, <span style="color: #2040a0">CultureInfo</span>.<span style="color: #2040a0">InvariantCulture</span><span style="color: #4444FF">)</span>, <span style="color: #444444">&quot;Billing&quot;</span>,
																	<span style="color: #0000FF"><strong>new</strong></span>
					<span style="color: #2040a0">CustomerAddress</span><span style="color: #4444FF">(</span><span style="color: #FF0000">0</span>, <span style="color: #2040a0">addressLine1</span>, <span style="color: #2040a0">addressLine2</span>, <span style="color: #2040a0">addressCity</span>,
									<span style="color: #2040a0">addressStateProvinceID</span>, <span style="color: #444444">&quot;&quot;</span>, <span style="color: #2040a0">addressPostalCode</span><span style="color: #4444FF">)</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>


				<span style="color: #008000">// Place Order</span>
				<span style="color: #2040a0">OrdersDB</span> <span style="color: #2040a0">orderSystem</span> <span style="color: #4444FF">=</span> <span style="color: #0000FF"><strong>new</strong></span> <span style="color: #2040a0">OrdersDB</span><span style="color: #4444FF">(</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
				<span style="color: #0000FF"><strong>int</strong></span> <span style="color: #2040a0">orderId</span> <span style="color: #4444FF">=</span> <span style="color: #2040a0">orderSystem</span>.<span style="color: #2040a0">PlaceOrder</span><span style="color: #4444FF">(</span><span style="color: #2040a0">customerId</span>, <span style="color: #2040a0">customerId</span>,
													 <span style="color: #008000">// Use default shipper for instant ordering</span>
													 <span style="color: #FF0000">1</span>,
													 <span style="color: #2040a0">isExtendedProcessing</span> ?
													 <span style="color: #2040a0">Constants</span>.<span style="color: #2040a0">Status</span>.
													 <span style="color: #2040a0">PendingInventoryCheck</span> <span style="color: #4444FF">:</span>
													 <span style="color: #2040a0">Constants</span>.<span style="color: #2040a0">Status</span>.<span style="color: #2040a0">Shipped</span>,
													 <span style="color: #2040a0">addressID</span>,
													 <span style="color: #008000">//Use the same address for billing and shipping</span>
													 <span style="color: #008000">//for API simplicity reasons, and security.</span>
													 <span style="color: #2040a0">addressID</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
																
				

				<span style="color: #008000">// Demonstrate service broker features if ExtendedOrderProcessing is true in web.config file.</span>
				<span style="color: #0000FF"><strong>if</strong></span> <span style="color: #4444FF">(</span><span style="color: #2040a0">isExtendedProcessing</span><span style="color: #4444FF">)</span>
				<span style="color: #4444FF"><strong>{</strong></span>
					<span style="color: #2040a0">ExtendedOrderProcessing</span> <span style="color: #2040a0">eop</span> <span style="color: #4444FF">=</span> <span style="color: #0000FF"><strong>new</strong></span> <span style="color: #2040a0">ExtendedOrderProcessing</span><span style="color: #4444FF">(</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>

					<span style="color: #2040a0">eop</span>.<span style="color: #2040a0">PostSalesOrder</span><span style="color: #4444FF">(</span><span style="color: #2040a0">orderId</span>, <span style="color: #2040a0">customerId</span>, <span style="color: #2040a0">orderSystem</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
				<span style="color: #4444FF"><strong>}</strong></span>

				
            
				<span style="color: #008000">// Return OrderDetails</span>
				<span style="color: #0000FF"><strong>return</strong></span> <span style="color: #2040a0">orderSystem</span>.<span style="color: #2040a0">GetOrderDetails</span><span style="color: #4444FF">(</span><span style="color: #2040a0">orderId</span>, <span style="color: #2040a0">customerId</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
			<span style="color: #4444FF"><strong>}</strong></span>
			<span style="color: #0000FF"><strong>else</strong></span> 
			<span style="color: #4444FF"><strong>{</strong></span>
				<span style="color: #008000">// invalid input </span>
				<span style="color: #0000FF"><strong>return</strong></span> <span style="color: #2040a0">null</span><span style="color: #4444FF">;</span>
			<span style="color: #4444FF"><strong>}</strong></span>
		<span style="color: #4444FF"><strong>}</strong></span>
     
		<span style="color: #008000">//*******************************************************</span>
		<span style="color: #008000">//</span>
		<span style="color: #008000">// InstantOrder.CheckStatus() Method </span>
		<span style="color: #008000">//</span>
		<span style="color: #008000">// The CheckStatus method enables a remote client to programmatically</span>
		<span style="color: #008000">// query the current status of an order in the AdventureWorks System. </span>
		<span style="color: #008000">//</span>
		<span style="color: #008000">//*******************************************************  </span>
     
		<span style="color: #4444FF">[</span><span style="color: #2040a0">WebMethod</span><span style="color: #4444FF">(</span><span style="color: #2040a0">Description</span><span style="color: #4444FF">=</span><span style="color: #444444">&quot;The CheckStatus method enables a remote client to programmatically query the current status of an order in the AdventureWorks System.&quot;</span>, <span style="color: #2040a0">EnableSession</span><span style="color: #4444FF">=</span><span style="color: #0000FF"><strong>false</strong></span><span style="color: #4444FF">)</span><span style="color: #4444FF">]</span>
		<span style="color: #0000FF"><strong>public</strong></span> <span style="color: #2040a0">OrderDetails</span> <span style="color: #2040a0">CheckStatus</span><span style="color: #4444FF">(</span><span style="color: #2040a0">string</span> <span style="color: #2040a0">userName</span>, <span style="color: #2040a0">string</span> <span style="color: #2040a0">password</span>, <span style="color: #0000FF"><strong>int</strong></span> <span style="color: #2040a0">orderID</span><span style="color: #4444FF">)</span> 
		<span style="color: #4444FF"><strong>{</strong></span>
     
			<span style="color: #008000">// Login client using provided username and password</span>
			<span style="color: #2040a0">CustomersDB</span> <span style="color: #2040a0">accountSystem</span> <span style="color: #4444FF">=</span> <span style="color: #0000FF"><strong>new</strong></span> <span style="color: #2040a0">CustomersDB</span><span style="color: #4444FF">(</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
			<span style="color: #2040a0">CustomerDetails</span> <span style="color: #2040a0">customerDetails</span> <span style="color: #4444FF">=</span> <span style="color: #2040a0">accountSystem</span>.<span style="color: #2040a0">Login</span><span style="color: #4444FF">(</span><span style="color: #2040a0">userName</span>, <span style="color: #2040a0">password</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
			<span style="color: #2040a0">String</span> <span style="color: #2040a0">customerId</span> <span style="color: #4444FF">=</span> <span style="color: #2040a0">customerDetails</span>.<span style="color: #2040a0">CustomerID</span><span style="color: #4444FF">;</span>
        
			<span style="color: #0000FF"><strong>if</strong></span> <span style="color: #4444FF">(</span><span style="color: #2040a0">customerId</span> <span style="color: #4444FF">=</span><span style="color: #4444FF">=</span> <span style="color: #2040a0">null</span><span style="color: #4444FF">)</span> 
			<span style="color: #4444FF"><strong>{</strong></span>
				<span style="color: #0000FF"><strong>throw</strong></span> <span style="color: #0000FF"><strong>new</strong></span> <span style="color: #2040a0">Exception</span><span style="color: #4444FF">(</span><span style="color: #444444">&quot;Error: Invalid Login!&quot;</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
			<span style="color: #4444FF"><strong>}</strong></span>
        
			<span style="color: #008000">// Return OrderDetails Status for Specified Order</span>
			<span style="color: #2040a0">OrdersDB</span> <span style="color: #2040a0">orderSystem</span> <span style="color: #4444FF">=</span> <span style="color: #0000FF"><strong>new</strong></span> <span style="color: #2040a0">OrdersDB</span><span style="color: #4444FF">(</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
			<span style="color: #0000FF"><strong>return</strong></span> <span style="color: #2040a0">orderSystem</span>.<span style="color: #2040a0">GetOrderDetails</span><span style="color: #4444FF">(</span><span style="color: #2040a0">orderID</span>, <span style="color: #2040a0">customerId</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
		<span style="color: #4444FF"><strong>}</strong></span>
	<span style="color: #4444FF"><strong>}</strong></span>
<span style="color: #4444FF"><strong>}</strong></span>
</pre>
